#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <cstring>

//user define
#include "axil_cmd.h"
#include "sensor_config.h"
#include "sensor_spi.h"
#include "sensor_user.h"

axil_cmd_handle sensor_user;

int sensor_user_setup(unsigned int baseAddr){
    return axil_cmd_setup(&sensor_user, baseAddr);
}

void sensor_user_reset(){
    axil_cmd_set(&sensor_user,USER_RESET_SENSOR,0x0);
    usleep(5);
    axil_cmd_set(&sensor_user,USER_RESET_SENSOR,0x1);
}

void sensor_user_training(){
    axil_cmd_set(&sensor_user,USER_START_TRAINING,0x1);
    while(axil_cmd_get(&sensor_user,USER_TRAINING_STATUS)!=0x1);
}

void sensor_user_rtl_reset(){
    axil_cmd_set(&sensor_user,USER_RESET_RTL,0x1);
}

void sensor_user_init_status(unsigned int user_init_status){
    axil_cmd_set(&sensor_user,USER_INIT_OK,user_init_status);
}

void sensor_user_texp0_gap(unsigned int texp0_gap_high,unsigned int texp0_gap_low){
    axil_cmd_set(&sensor_user,USER_TEXP0_GAP_LOW,texp0_gap_low);
    axil_cmd_set(&sensor_user,USER_TEXP0_GAP_HIGH,texp0_gap_high);
}

void sensor_user_camera_mode(unsigned int user_camera_mode){
    axil_cmd_set(&sensor_user,USER_CAMERA_MODE,user_camera_mode);
}

void sensor_user_photo_mode(unsigned int user_photo_mode){
    axil_cmd_set(&sensor_user,USER_PHOTO_MODE,user_photo_mode);
}

void sensor_user_trigger_once(){
    axil_cmd_set(&sensor_user,USER_TRIGGER,0x1);
}



